package com.yiwei.ydd.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.PopBigGifModel;
import com.yiwei.ydd.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class RegisterDialogAdapter extends ItemAdapter<PopBigGifModel.DatasBean, RegisterDialogAdapter.DefaultHolder> {


    private final int x30;
    private final int x80;

    private Context context;

    public RegisterDialogAdapter(Context context) {
        super(context);
        this.context = context;
        x30 = context.getResources().getDimensionPixelSize(R.dimen.x30);
        x80 = context.getResources().getDimensionPixelSize(R.dimen.x80);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_register_success, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        PopBigGifModel.DatasBean item = getItem(position);
        Spanned text = Spans.with(context).font("￥", x30, 0xffffffff).
                font(item.par.replace(".00", "").replace(".0", ""), x80, 0xffffffff).
                build();
        holder.txtLeft.setText(text);
        holder.txtRight.setText("充值\n满" + item.use_limit + "可使用");

        holder.btnTotal.setShapeGradientStartColor(Color.parseColor(item.color.l)).setShapeGradientEndColor(Color.parseColor(item.color.r)).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
        holder.btnTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick("");
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.btn_total)
        SuperButton btnTotal;
        @BindView(R.id.txt_left)
        TextView txtLeft;
        @BindView(R.id.txt_right)
        TextView txtRight;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String name);
    }
}
